<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>门店管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
	   
		$(document).ready(function() {
			checkSize();
			yzCode();
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				rules:{          
					cnName:{required:true,stringCheck:true}, 
					code:{required:true,codes:true,code:true},
					remarks:{remarkCheck:true} ,
	            },
	           
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			jQuery.validator.addMethod("stringCheck", function(value, element) {
				return this.optional(element) || /^[\u4e00-\u9fa5][\u4e00-\u9fa5a-zA-Z0-9]{1,9}$/.test(value);
               
			}, "2-10个字符，以汉字开头，可带字母或数字");
			jQuery.validator.addMethod("codes", function(value, element) {
				return this.optional(element) || /^[a-zA-Z0-9]{2,10}$/.test(value);
			}, "2-10个数字或字母");
			
			jQuery.validator.addMethod("remarkCheck", function(value,  
	                element, param) { 
				if(value.length>200){
					return false;
				} else{
					return true;
	            }
	        }, $.validator.format("字数超限"));
			$("#remarks").keyup(function(){
				checkSize();
			})
			
			jQuery.validator.addMethod("code", function(value,  
	                element, param) { 
				   var stg=$("#stgs").val();
				   if(stg==1){
					   return false;
				   }else{
					   return true;
				   }
				    
	        }, $.validator.format("仓库代码重复"));
			
		});
		function checkSize(){
			var curLength=$("#remarks").val().length;
			if(curLength>100){
				$("#textLength").css("color","red");
				$("#textLength").text(curLength+"/100");
			}else{
				$("#textLength").css("color","");
				$("#textLength").text(curLength+"/100");
			}
		}
		
		function yzCode(){
			var code=$("#code").val();
			var id=$("#storehouseId").val();
			 $.ajax({
			    	type:"post",
			    	data:{"code":code,"id":id},
			    	dataType:"json",
			    	url:"${ctx}/sys/storeWarehouse/yzCode",
			    	success:function(data){
			    		if(data.st==1){
			    			$("#stgs").val(1)
			    		}else{
			    			$("#stgs").val(0)
			    		}
			    	}
			    })
		}
	</script>
</head>
<body>
    <input name="stgs" id="stgs" type="hidden"/>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/storeWarehouse/">门店仓库列表</a></li>
		<li class="active"><a href="${ctx}/sys/storeWarehouse/form?id=${storeWarehouse.id}">门店仓库<shiro:hasPermission name="sys:storeWarehouse:edit">${not empty storeWarehouse.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:storeWarehouse:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="storeWarehouse" action="${ctx}/sys/storeWarehouse/save" method="post" class="form-horizontal">
		<form:hidden path="id" id="storehouseId"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">所属门店：</label>
			<div class="controls">
				<form:select id="storeCode" path="storeCode" class="input-medium required">
				<form:option value="" label="请选择"/>
			    <form:options items="${store}" htmlEscape="false" itemValue="code" itemLabel="cnName"/></form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">仓库代码：</label>
			<div class="controls">
				<form:input path="code" htmlEscape="false" maxlength="50" class="input-xlarge required" onchange="yzCode()" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">仓库名称：</label>
			<div class="controls">
				<form:input path="cnName" htmlEscape="false" maxlength="50" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
			    <span id="textLength" style="margin-top: 74px;position: absolute;line-height: 1; margin-left: 475px;color: red;">0/100</span>
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:storeWarehouse:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>